home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: judgemi@ix.netcom.com(Michael Judge )
- Newsgroups: comp.lang.c++
- Subject: Re: Scan a file. Urgent!!!!!!
- Date: 11 Feb 1996 23:35:51 GMT
- Organization: Netcom
- Message-ID: <4flugn$hj6@ixnews3.ix.netcom.com>
- References: <1996Feb11.120142.113766@kuhub.cc.ukans.edu>
- NNTP-Posting-Host: ix-bst-ma1-19.ix.netcom.com
- X-NETCOM-Date: Sun Feb 11 3:35:51 PM PST 1996
-
- In <1996Feb11.120142.113766@kuhub.cc.ukans.edu> moxu@kuhub.cc.ukans.edu
- writes:
- >
- > A data file has integers, a few characters. I want to read the
- content
- >out and assign integer values in the file into an array. I use
- "fscanf". The
- >things is when I use "fscanf(datafile,"%d",&digit)", the execution
- halted when
- >a character was encounted, probably because this sentence returns
- "NULL". So, I
- >can't read through the file and assign all the data into the array.
- > Urgent! The project is due Wednesday and now I haven't even set
- up the array
- >yet!
- > Any hint will be highly appreciated!
- > Thanks a lot!
-
- off the top of my head i think the problem here is that you are trying
- to scan an integer and since it doesnt find one it leaves the file
- pointer right where it is. If you want to read in an integer and maybe
- there is a character then you should read a character at a time and
- check if its an integer or not if it is proceed to check the next
- character and if its >='0' and <='9' then multiply first by 10 and add
- the second until you dont find a number. then go to the next number
- ect. maybe there is a more slick way to do this but this is just a
- quick answer.
-
-
-